package main

import (
	. "SGEngine2"
	"SGEngine2/SGUI"
)

func main() {
	View{
		Width:  640,
		Height: 480,
		Title:  "T^T",
		ViewScene: &Scene{
			InitFunc: InitScene,
			RootNode: ZeroNode(),
			Camera: Camera{
				CameraNode: ZeroNode(),
				BGColor:    Color3{0.6, 0.6, 0.6},
			}},
	}.Run()
}

var MenuNode *Node
var tw *SGUI.TopWidget

func InitScene(scene *Scene) {
	ShaderFolderPath = "../../Shader/"
	tw = SGUI.SGMLGlobal.LoadTopWidget("TestMenu.tpl", GenMenuData(), scene.RootNode)

	EventManager.AddGlobalEvent(GEVENT_MOUSEDOWN, MouseDown)

}

func MouseDown(x, y, b, s int) {
	MenuNodeV, _ := tw.JsEngine.Get("CurMenuId")
	MenuNodeStr := MenuNodeV.String()

	if MenuNodeStr == "" {
		return
	}
	MenuNode = tw.GetId(MenuNodeStr).(*SGUI.TopWidget).GetId("Root").GetWidgetInfo().Node
	bb := EventManager.EventCatch(RootView.ViewScene.RootNode, MenuNode, x, y, EVENT_MOUSEDOWN)
	if MenuNode.Active() && bb == false {
		MenuNode.SetActive(false)
	}
}

type MenuItemData struct {
	Text      string
	Id        string
	TextColor string
	BGColor   string
}

func GenMenuData() map[string]interface{} {
	Data := make(map[string]interface{})

	FileMenus := []MenuItemData{
		MenuItemData{"新建项目", "File_New", "", ""},
		MenuItemData{"打开项目", "File_Open", "", ""},
		MenuItemData{"保存项目", "File_Save", "", ""},
		MenuItemData{"小阿波", "File_Save", "", ""},
	}
	Data["FileMenu"] = FileMenus

	AboutMenus := []MenuItemData{
		MenuItemData{"干", "File_New", "", ""},
		MenuItemData{" 死", "File_Open", "", ""},
		MenuItemData{"  卡", "File_Save", "", ""},
		MenuItemData{"   鲁", "File_Save", "", ""},
		MenuItemData{"    宾", "File_Save", "", ""},
	}
	Data["AboutMenu"] = AboutMenus
	return Data
}
